import { defineStore } from "pinia";
import { computed, ref } from "vue";

// 定义 store
// defineStore(仓库的唯一标识，()=>{...})
export const useCounterStore = defineStore('counter',()=>{
  // 声明数据 state
  const count = ref(100)

  // 声明操作数据的方法 action (普通函数)
  const addCount = (val)=>{
    count.value +=val
  }
  const subCount = (val)=>{
    count.value +=val
  }
  // 声明基于数据派生的计算属性 getter
  const compCount = computed(()=>count.value*2)

  const message =ref('我是第二个数据')
  return {
    count,
    message,
    addCount,
    subCount,
    compCount
  }
},{
  persist:{
    key:'my-counter-store',
    pick:['count'] //只存储count 不存储 message
  }
})
